/*
 * KDRayTracer.h
 *
 *  Created on: Mar 21, 2009
 *      Author: steveca
 */

#ifndef __KDRAYTRACER_H__
#define __KDRAYTRACER_H__

#include "Prerequisite.h"
#include "RayTracer.h"

#define MAX_TRACE_DEPTH 4
#define SAMPLES 128

namespace RTRT {

	class KDTreeNode;
	typedef struct _NodeStackElem
	{
		KDTreeNode* node;
		float t;
		Vector3 pb;
		int prev, dummy1, dummy2;
	} NodeStackElem;
	
	
	class KDRayTracer : IRayTracer
	{
	public:
		KDRayTracer();
		virtual ~KDRayTracer();
	
	public:
		int initialise();
		
		int findNearest(Ray& ray, float& distance, Triangle& triangle);
		int findOccluder(Ray& ray, float& distance);
		Triangle *rayTrace(Ray& ray, Color& color, int depth, float index, float distance, float samples, float scale);
		float calcShade(Light *light, Vector3& intersectPoint, Vector3& direction, float samples, float scale);
		
		
	protected:
		int *m_mod; 
		SceneManager *m_sceneManager;
		 
		// For traversal
		NodeStackElem *m_nodeStack;
		
		// Counters
		int m_intersections;
		int m_raysCast;
	};

}


#endif /* KDRAYTRACER_H_ */
